package com.nxmu.hire.controller;

import com.nxmu.hire.common.exception.ServiceException;
import com.nxmu.hire.common.util.ResponseResult;
import com.nxmu.hire.service.ApplyService;
import com.nxmu.hire.vo.ApplyReqVo;
import com.nxmu.hire.vo.ApplyResVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping(value = "/apply")
public class ApplyController {

    @Autowired
    private ApplyService applyService;

    @PostMapping(value = "/apply")
    public ResponseResult apply(@Valid @RequestBody ApplyReqVo applyReqVo){
        ApplyResVo applyResVo = null;
        try {
            applyResVo = applyService.save(applyReqVo);
        } catch (ServiceException e) {
            return ResponseResult.fail(e.getMessage());
        }
        return ResponseResult.success(applyResVo);
    }

}
